﻿@{
    Layout = "_FinanceLayout";
}
<fieldset class="layui-elem-field" style="margin: 20px">
    <legend>个人工资</legend>
    <div class="layui-field-box" style="display:inline-block">
        <form class="layui-form" action="" lay-filter="example" style="width:50%;">

            <div class="layui-container">
                <div class="layui-row">
                    <div class="layui-col-md5">
                        <div class="layui-form-item">
                            <label class="layui-form-label">教师工号</label>
                            <div class="layui-input-block">
                                <input type="text" name="username" lay-verify="title" autocomplete="off" value="T16060701004" placeholder="请输入教师工号" class="layui-input" id="teacherid" style="width:200px;">
                            </div>
                        </div>
                    </div>

                    <div class="layui-col-md2">
                        <div class="layui-form-item" style="display:inline-block">
                            <label class="layui-form-label">请输入日期</label>
                            <div class="layui-input-block">
                                <input type="text" name="username" lay-verify="title" autocomplete="off" placeholder="请选择年份" class="layui-input" id="picker4" style="width:160px;" readonly>
                            </div>
                        </div>
                    </div>

                    <div class="layui-col-md3">
                        <div class="layui-form-item">
                            <div class="layui-form-item" style="display:inline-block">
                                <div class="layui-input-block" style="width:150px;">
                                    <select name="interest2" lay-filter="aihao2" id="month0" style="width:150px;">
                                        <option value="">请选择月份</option>
                                        <option value="-01">-01</option>
                                        <option value="-02">-02</option>
                                        <option value="-03">-03</option>
                                        <option value="-04">-04</option>
                                        <option value="-05">-05</option>
                                        <option value="-06">-06</option>
                                        <option value="-07">-07</option>
                                        <option value="-08">-08</option>
                                        <option value="-09">-09</option>
                                        <option value="-10">-10</option>
                                        <option value="-11">-11</option>
                                        <option value="-12">-12</option>
                                    </select>
                                </div>
                            </div>

                        </div>
                    </div>

                    <div class="layui-col-md1">
                        <div class="layui-form-item">
                            <button type="button" class="layui-btn" id="view">查看</button>
                        </div>
                    </div>

                </div>
            </div>
        </form>
    </div>
    <div style="padding:15px ;margin-top:-40px">
        <table class="layui-hide,layui-form" id="test" lay-filter="test"></table>
    </div>

</fieldset>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit" id="edit2">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>


@section Scripts{
    <script src="~/js/jquery.js"></script>
    <script src="~/layui-v2.5.5/layui/layui.js"></script>
    <script>
        layui.use('form', function(){
          var form = layui.form;
          form.render();
        });
        $(function () {
           var yearr = '';
            layui.use(['layer', 'laydate'], function () {
                var laydate = layui.laydate;
                //时间选择器(年)
                laydate.render({
                    elem: '#picker4',
                    theme: 'molv',
                    type: 'year',
                    btns: ['now'],
                    max: new Date().getYear(),//getNowFormatDate(), //getNowFormatDate is not defined
                    ready: function (date) {
                        $("#layui-laydate4").off('click').on('click', '.laydate-year-list li', function () {
                            $("#layui-laydate4").remove();
                        });
                    },
                    change: function (value, dates, edate) {
                        var year = $('#picker4').val(value);
                        yearr = value;
                    }
                });
            });

            layui.use('table', function () {
                var table = layui.table;
                $.ajax({
                    url: '/Api/QueryTeacherWage',
                    data: "",
                    success: function (data) {  //当请求成功时运行的函数；变量：接受服务器响应结果的值
                if (data.code == 200)
                                {
                                    table.render({
                                        elem: '#test'
                                        , title: 'wage Table'
                                        , page: true //开启分页
                                       // ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
                                        ,defaultToolbar: ['filter']
                                        , cols: [[ //表头
                                           { field:'teacherid', title: '教师工号', sort: true, fixed: 'left' }
                                            , { field: 'wagetime', templet: '<div>{{d.wagetime.slice(0,7)}}</div>', title: '日期', sort: true }
                                            , { field: 'basicwage', title: '基本工资' }
                                            , { field: 'overtimewage', title: '加班工资', sort: true }
                                            , { field: 'welfare', title: '福利补贴', }
                                            , { field: 'bonus', title: '奖金' }
                                            , { field: 'totalwage', title: '总计', sort: true }
                                            ,{fixed: 'right', title:'操作', toolbar: '#barDemo'}

                                        ]]
                                        , data: data.wageList
                                        , even: true
                                    });
                                }
                                if (data.code != 200)
                                {
                                    layer.msg("查询失败，无给定月工资记录！");
                                }
                    },
                })
                // 工具栏监听
                table.on('tool(test)', function (obj) {
                    var data = obj.data;
                    if (obj.event === 'del') {
                        layer.confirm('真的删除行么', function (index) {
                            $.ajax({
                                url: "/Api/DeleteTeacherWage",
                                type: "POST",
                                data: { id: data.id },
                                success: function (data) {
                                    if (data.code == 200) {
                                        //删除这一行
                                        obj.del();
                                        //关闭弹框
                                        layer.close(index);
                                        layer.msg("删除成功", { icon: 6 });
                                    } else {
                                        layer.msg("删除失败", { icon: 5 });
                                    }
                                }
                            });
                            //obj.del();
                            //layer.close(index);
                        });
                    } else if (obj.event === 'edit') {
                        layer.open({
                            type: 2,
                            area: ['380px', '510px'],
                            resize: false,
                            content: '/cwc/EditWage?teacherid=' + data.teacherid + '&time=' + data.wagetime,
                            title: '我的工资',
                        });                       
                    }
                });
            });



            $("#view").on("click", function () {
                var teacheridd = '';
                var monthh = '';
                teacheridd = $("#teacherid").val();//获取老师id
                monthh = $("#month0 option:selected").val(); //获取月
                var yearmonth = yearr + monthh;
                if (teacheridd == "") {
                    layer.msg('请填写所查寻教师工号', { icon: 7, time: 1500, shade: [0.3, '#000', true] });
                } else {
                layui.use('table', function () {
                    var table = layui.table;
                        $.ajax({
                            url: '/Api/QueryTeacherWage',
                            data: {
                                'teacherid': teacheridd,
                                'year':yearr,
                                'time': yearr + monthh,
                                'month': monthh
                            },
                            success: function (data) {  //当请求成功时运行的函数；变量：接受服务器响应结果的值

                                table.render({
                                    elem: '#test'
                                    , title: 'wage Table'
                                    , page: true //开启分页
                                   // ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
                                    ,defaultToolbar: ['filter']
                                    , cols: [[ //表头
                                        { field: 'wagetime', templet: '<div>{{d.wagetime.slice(0,7)}}</div>',title: '日期', sort: true, fixed: 'left' }
                                        , { field: 'basicwage', title: '基本工资' }
                                        , { field: 'overtimewage', title: '加班工资', sort: true }
                                        , { field: 'welfare', title: '福利补贴', }
                                        , { field: 'bonus', title: '奖金' }
                                        , { field: 'totalwage', title: '总计', sort: true }
                                        ,{fixed: 'right', title:'操作', toolbar: '#barDemo'}

                                    ]]
                                    , data: data.wageList
                                    , even: true
                                });
                            },
                        })
                       // 工具栏监听
                        table.on('tool(test)', function(obj){
                             var data = obj.data;
                               if(obj.event === 'del'){
                                   layer.confirm('真的删除行么', function (index) {
                                       $.ajax({
                                           url: "/Api/DeleteTeacherWage",
                                           type: "POST",
                                           data: { id: data.id },
                                           success: function (data) {
                                                if (data.code == 200) {
                                                    //删除这一行
                                                    obj.del();
                                                    //关闭弹框
                                                    layer.close(index);
                                                    layer.msg("删除成功", {icon: 6});
                                                } else {
                                                    layer.msg("删除失败", {icon: 5});
                                                }
                                            }
                                        });
                                       //obj.del();
                                      //layer.close(index);
                                    });
                               } else if (obj.event === 'edit') {
                                    layer.open({
                                    type:2,
                                    area: ['380px', '510px'],
                                    resize: false,
                                    content: '/cwc/EditWage?teacherid=' + teacheridd + '&time=' + data.wagetime,
                                    title:'我的工资',
                                    })
                                   form.val('test', {
                                        "teacherid": WageData.wage.teacherid
                                        , "wagetime": WageData.wage.wagetime.substring(0,7)
                                        , "basicwage": WageData.wage.basicwage
                                        , "overtimewage": WageData.wage.overtimewage
                                        , "welfare": WageData.wage.welfare
                                        , "bonus": WageData.wage.bonus
                                        , "totalwage": WageData.wage.totalwage
                                    });
                               }
                        });
                });
                }


            })
        });
    </script>
}


